package com.css.zfzx.fxpg.modules.boundary.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.css.bpm.platform.utils.*;
import com.css.zfzx.fxpg.common.utils.BeanUtil;
import com.css.zfzx.fxpg.common.utils.CheckObjFields;
import com.css.zfzx.fxpg.common.utils.VectorDataUtil;
import com.css.zfzx.fxpg.modules.boundary.repository.BoundaryNativeRepository;
import com.css.zfzx.fxpg.modules.boundary.repository.entity.BoundaryEntity;
import com.css.zfzx.fxpg.modules.boundary.service.BoundaryService;
import com.css.zfzx.fxpg.modules.boundary.viewobjects.BoundaryQueryParams;
import com.css.zfzx.fxpg.modules.levelmap.casualty.repository.FxCasualtyLevelMapImport;
import com.css.zfzx.fxpg.modules.levelmap.casualty.repository.FxCasualtyLevelMapNativeRepository;
import com.css.zfzx.fxpg.modules.levelmap.casualty.repository.FxCasualtyLevelMapRepository;
import com.css.zfzx.fxpg.modules.levelmap.casualty.repository.entity.FxCasualtyLevelMapEntity;
import com.css.zfzx.fxpg.modules.levelmap.casualty.viewobjects.FxCasualtyLevelMapQueryParams;
import com.css.zfzx.fxpg.modules.levelmap.casualty.viewobjects.FxCasualtyLevelMapVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.*;

/**
 * @author andy
 * @date 2021-01-26
 */
@Service
@Slf4j
public class BoundaryServiceImpl implements BoundaryService {

    @Autowired
    private BoundaryNativeRepository boundaryNativeRepository;

    @Override
    public JSONObject getBoundaries(BoundaryQueryParams queryParams) {
        JSONObject jsonObject = new JSONObject();
        List<BoundaryEntity> boundaryEntities = this.boundaryNativeRepository.listBoundaries(queryParams);
        for (BoundaryEntity boundaryEntity : boundaryEntities) {
            String coords = boundaryEntity.getCoordinate();
            if (coords == null) continue;
            coords = coords.substring(coords.indexOf("(((") + 3, coords.lastIndexOf(")))"));
            coords = coords.replace(")), ((", "|");
            coords = coords.replace("), (", "#");
            coords = coords.replace(", ", ";");
            coords = coords.replace(" ", ",");
            jsonObject.put(boundaryEntity.getName(), coords);
        }
        return jsonObject;
    }
}
